<?php
	class hopdongtindungdb
	{
		public function Them($SoKheUoc = "",
							 $SoHDTC = "", 
							$QuanHeVoiKH = "",
					
							$SoThangVay = 0,
							$LaiSuatQuaHan = 0,
							 $SoTienVay = 0,
						     $MucDichChoVay = "",
							 $NgayLapHopDong = "",
							 $NgayDenHan = "",
							 $HinhThucXuLy = "",
							 $MaKyHanTra = 0)
		{
			$sql = "INSERT INTO hopdongtindung(SoKheUoc, SoHDTC, QuanHeVoiKH, SoThangVay, LaiSuatQuaHan, SoTienVay, MucDichChoVay, NgayLapHopDong, NgayDenHan, HinhThucXuLy, MaKyHanTra)
					VALUES('$SoKheUoc',
							 '$SoHDTC',
							 '$QuanHeVoiKH',
						
							 $SoThangVay,
							 $LaiSuatQuaHan,
							 $SoTienVay,
							 '$MucDichChoVay',
							 '$NgayLapHopDong',
							 '$NgayDenHan',
							 '$HinhThucXuLy',
							 $MaKyHanTra)";	
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function ThemHopDongTinDung($SoKheUoc = "",
				$SoHDTC = "",
				$QuanHeVoiKH = "",
			
				$SoThangVay = 0,
				$LaiSuatQuaHan = 0,
				$SoTienVay = 0,
				$MucDichChoVay = "",
				$NgayLapHopDong = "",
				$NgayDenHan = "",
				$HinhThucXuLy = "",
				$MaKyHanTra = 0)
		{
			$sql = "INSERT INTO hopdongtindung(SoKheUoc, SoHDTC, QuanHeVoiKH, SoThangVay, LaiSuatQuaHan, SoTienVay, MucDichChoVay, NgayLapHopDong, NgayDenHan, HinhThucXuLy, MaKyHanTra)
			VALUES('$SoKheUoc',
			'$SoHDTC',
			'$QuanHeVoiKH',
		
			$SoThangVay,
			$LaiSuatQuaHan,
			$SoTienVay,
			'$MucDichChoVay',
			'$NgayLapHopDong',
			'$NgayDenHan',
			'$HinhThucXuLy',
			$MaKyHanTra)";
						
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($SoKheUoc = "",
							 	$SoHDTC = "", 
								$QuanHeVoiKH = "",
							
								$SoThangVay = 0,
								$LaiSuatQuaHan = 0,
							 	$SoTienVay = 0,
						     	$MucDichChoVay = "",
							 	$NgayLapHopDong = "",
							 	$NgayDenHan = "",
							 	$HinhThucXuLy = "",
							 	$MaKyHanTra = 0)
		{
			$sql = "UPDATE hopdongtindung SET 
			QuanHeVoiKH = '$QuanHeVoiKH',
			SoThangVay = $SoThangVay,
			LaiSuatQuaHan = $LaiSuatQuaHan,
			SoTienvay = $SoTienVay,
			MucDichChoVay = '$MucDichChoVay',
			NgayLapHopDong = '$NgayLapHopDong',
			NgayDenHan = '$NgayDenHan',
			HinhThucXuLy = '$HinhThucXuLy'";
		
			if($SoHDTC != "")
				$sql .= ", SoHDTC = '$SoHDTC'";
			
			if($MaKyHanTra > 0)
				$sql .= ", MaKyHanTra = $MaKyHanTra";
			
			
			$sql .= " WHERE SoKheUoc = '$SoKheUoc'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($SoKheUoc = "",
							 		$SoHDTC = "", 
									$QuanHeVoiKH = "",
								
									$SoThangVay = 0,
									$LaiSuatQuaHan = 0,
							 		$SoTienVay = 0,
						     		$MucDichChoVay = "",
							 		$NgayLapHopDong = "",
							 		$NgayDenHan = "",
							 		$HinhThucXuLy = "",
							 		$MaKyHanTra = 0)
		{
			$sql = "SELECT * 
					FROM hopdongtindung
					WHERE (1)";
			
			if($SoKheUoc != "")
				$sql .= " AND SoKheUoc = '$SoKheUoc'";
			
			if($SoHDTC != "")
				$sql .= " AND SoHDTC = '$SoHDTC'";	

			if($QuanHeVoiKH != "")
				$sql .= " AND QuanHeVoiKH = '$QuanHeVoiKH'";
			
				
			if($SoThangVay > 0)
				$sql .= " AND SoThangVay = $SoThangVay";
				
				
			if($LaiSuatQuaHan > 0)
				$sql .= " AND LaiSuatQuaHan = $LaiSuatQuaHan";			
			
			if($SoTienVay > 0)
				$sql .= " AND SoTienVay = $SoTienVay";
			
			if($MucDichChoVay != "")
				$sql .= " AND MucDichChoVay = '$MucDichChoVay'";
			
			if($NgayLapHopDong != "")
				$sql .= " AND NgayLapHopDong = '$NgayLapHopDong'";
				
			if($NgayDenHan != "")
				$sql .= " AND NgayDenHan = '$NgayDenHan'";
			
			if($HinhThucXuLy != "")
				$sql .= " AND HinhThucXuLy = '$HinhThucXuLy'";
			
			if($MaKyHanTra > 0)
				$sql .= " AND MaKyHanTra = $MaKyHanTra";

			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>